<?php


namespace App\Controller\Cooperative;


use App\Annotation\OperationLog;
use App\Controller\AbstractController;
use App\Request\Cooperative\ConfigBannerBlockRequest;
use App\Request\Cooperative\ConfigBannerCreateRequest;
use App\Request\Cooperative\ConfigBannerUpdateRequest;
use App\Service\Cooperative\ConfigBannerService;
use App\Service\Cooperative\ConfigDiscoverService;
use Hyperf\Di\Annotation\Inject;

class ConfigDiscoverController extends AbstractController
{

    /**
     * @Inject()
     * @var ConfigDiscoverService
     */
    protected $configDiscoverService;

    /**
     * @OperationLog(event="配置中心-发现页列表",platform="cooperative")
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function index()
    {
       $data = $this->configDiscoverService->index();
       return $this->response->success($data);
    }

    /**
     * @OperationLog(event="配置中心-添加发现页",platform="cooperative")
     * @param ConfigBannerCreateRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function create(ConfigBannerCreateRequest $request)
    {
       $data = $this->configDiscoverService->save(null, $request->validated());
       return $this->response->success($data);

    }

    /**
     * @OperationLog(event="配置中心-修改发现页",platform="cooperative")
     * @param int $id
     * @param ConfigBannerUpdateRequest $request
     * @return mixed|\Psr\Http\Message\ResponseInterface
     */
    public function update(int $id, ConfigBannerUpdateRequest $request)
    {
       $data = $this->configDiscoverService->save($id, $request->validated());
       return $this->response->success($data);
    }

    /**
     * @OperationLog(event="配置中心-删除发现页",platform="cooperative")
     * @param int $id
     * @return mixed|\Psr\Http\Message\ResponseInterface
     * @throws \Exception
     */
    public function delete(int $id)
    {
       $data = $this->configDiscoverService->delete($id);
       return $this->response->success($data);
    }


}